package com.oto.model;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * @author xueqiang.mi
 * @since 2011-1-14
 */
@PersistenceCapable(table = "Queue", identityType = IdentityType.APPLICATION)
public class QueueDO implements Serializable {
	private static final long serialVersionUID = -638606750931574064L;

	public static final String TYPE_USER = "user";
	public static final String TYPE_PACK = "pack";
	public static final String TYPE_FLOW = "flow";

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private String from;
	@Persistent
	private String to;
	@Persistent
	private String owner;
	@Persistent
	private String type;
	@Persistent
	private long dataId;
	@Persistent
	private Date crtDate;

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		QueueDO other = (QueueDO) obj;
		if (crtDate == null) {
			if (other.crtDate != null)
				return false;
		} else if (!crtDate.equals(other.crtDate))
			return false;
		if (dataId != other.dataId)
			return false;
		if (from == null) {
			if (other.from != null)
				return false;
		} else if (!from.equals(other.from))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (owner == null) {
			if (other.owner != null)
				return false;
		} else if (!owner.equals(other.owner))
			return false;
		if (to == null) {
			if (other.to != null)
				return false;
		} else if (!to.equals(other.to))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}

	public Date getCrtDate() {
		return crtDate;
	}

	public Long getDataId() {
		return dataId;
	}

	public String getFrom() {
		return from;
	}

	public Long getId() {
		return id;
	}

	public String getOwner() {
		return owner;
	}

	public String getTo() {
		return to;
	}

	public String getType() {
		return type;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((crtDate == null) ? 0 : crtDate.hashCode());
		result = prime * result + (int) (dataId ^ (dataId >>> 32));
		result = prime * result + ((from == null) ? 0 : from.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((owner == null) ? 0 : owner.hashCode());
		result = prime * result + ((to == null) ? 0 : to.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	public void setCrtDate(Date crtDate) {
		this.crtDate = crtDate;
	}

	public void setDataId(Long dataId) {
		this.dataId = dataId;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public void setTo(String to) {
		this.to = to;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Override
	public String toString() {
		return "QueueDO [id=" + id + ", from=" + from + ", to=" + to + ", crtDate=" + crtDate + ", type=" + type
				+ ", owner=" + owner + ", dataId=" + dataId + "]";
	}
}
